import { Button } from 'antd';
import { ColumnsType } from 'antd/es/table';
import { IntervalTableData } from '.';
import { useNumberWithUnit } from '@app-base/common/hooks/unit';
import { ParameterObjectType } from '@amcax/base';

const Distance = ({ value }: { value: number }) => {
  const { parseNumberWithUnit } = useNumberWithUnit();
  return parseNumberWithUnit(value, ParameterObjectType.Length, 3);
};

export const getIntervalCheckColumns: (
  setTableRowIgnored: (key: string, ignored: boolean) => void,
) => ColumnsType<IntervalTableData> = (setTableRowIgnored) => [
  {
    title: '间隙',
    key: 'label',
    width: 120,
    render() {
      return '重合或干涉';
    },
  },
  {
    title: '零件1',
    width: 100,
    render(_, record) {
      const title = record.part1?.title;
      return record.index1 == null ? title : `${title}的实体${record.index1}`;
    },
  },
  {
    title: '零件2',
    width: 100,
    render(_, record) {
      const title = record.part2?.title;
      return record.index2 == null ? title : `${title}的实体${record.index2}`;
    },
  },
  {
    title: '计算结果',
    dataIndex: 'distance',
    key: 'distance',
    width: 120,
    render(val: number) {
      return <Distance value={val} />;
    },
  },
  {
    title: '',
    key: 'operation',
    dataIndex: 'isIgnored',
    width: 120,
    render(ignored: boolean, row) {
      return (
        <Button
          className='min-w-[90px]'
          onClick={() => {
            setTableRowIgnored(row.key, !ignored);
          }}
        >
          {ignored ? '取消忽略' : '忽略'}
        </Button>
      );
    },
  },
];
